<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>闭包问题</title>
</head>
<body>
    <button id="btn">Add</button>

    <script>
        function foo() {
            var el = document.getElementById('btn');
            el.onclick = function() {
                console.log(el.id)
            }
        }

        foo()


        function foo() {
            var el = document.getElementById('btn');
            el.onclick = function() {
                console.log(el.id)
            }

            el = null
        }
        
        foo()

        function foo() {
            const el = document.getElementById('btn');
            el.onclick = function() {
                console.log(el.id)
            }
        }
        foo()
    </script>
</body>
</html>